<?php
(!defined('IN_TOA') || !defined('IN_ADMIN')) && exit('Access Denied!');
/*
	[天生创想] (C)2008-2011 515158 Inc.
	This is NOT a freeware, use is subject to license terms
    URL:http://www.515158.com/
*/

//if ( !is_superadmin() && !check_purview('manage_link') ) prompt('对不起，你没有权限执行本操作！');

empty($do) && $do = 'list';
if ($do == 'list') {
	//列表信息 
	$wheresql = '';
	$page = max(1, getGP('page','G','int'));
	$pagesize = 20;
	$offset = ($page - 1) * $pagesize;
	$url = 'admin.php?ac=departmentname&fileurl=public';

	if ($keyword = getGP('keyword','G')) {
		$wheresql .= " AND (name LIKE '%$keyword%' OR persno LIKE '%$keyword%')";
		$url .= '&keyword='.rawurlencode($keyword);
	}
	if ($fatherid = getGP('fatherid','G','int')) {
		$wheresql .= " AND father = $fatherid";
		$url .= '&fatherid='.$fatherid;	
	}else
	{
		$wheresql .= " AND father ='0'";
	}
	
	//$num = $db->result("SELECT COUNT(*) AS num FROM ".DB_TABLEPRE."department a WHERE 1 $wheresql");
     $sql = "SELECT * FROM ".DB_TABLEPRE."department WHERE 1 $wheresql ORDER BY id ASC LIMIT $offset, $pagesize";
	$result = $db->fetch_all($sql);

	include_once('template/departmentname.php');

}
//读取部门
function get_department_cok($fatherid=0,$selid=0,$layer=0 ,$style=10)
{


	$str='';
    global $db;
	$query = $db->query("SELECT * FROM ".DB_TABLEPRE."department where father='$fatherid' ORDER BY id Asc  ");
	
	if(count($query)>0){
	   for($i=0;$i<$layer;$i++){
	   
	   $str.='style="padding-left:'.$style.'px;"';
	   
	  }
	
	while ($row = $db->fetch_array($query)) {
	//$selstr = $row['id'] == $selid ? 'selected="selected"' : '';
	
	//$htmlstr= '<option value="'.$row['id'].'"  '.$selstr.'>'.$str.$row['name'].'</option>';
	$htmlstr='<tr><td height="25" '.$str.'><input type="checkbox" name="department[]" value="'.$row['name'].'" style="border:0px;" /> '.$row['name'].'</td></tr>';
	
	echo $htmlstr."";

	get_department_cok($row['id'],$selid,$layer+1,$style+20);
	
	}

	}
	
   return ;

}


//echo "<a href='admin.php?ac=save&fileurl=public'>1111</a>";
//closedir($ml);
?>
